<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
    $fields=array('id','saletype','star','tuijie','paixu','title','image','address','userid','province','district','city');
    $orderby='paixu desc,tuijie desc, star desc, id desc';
	$total='';
	$return['list']=pdo_getslice('jy_jd_hotel',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($return['list'] as &$v){
		if($v['userid']){
			$v['is']=1;
			$v['merchtitle']=pdo_getcolumn('jy_jd_user',array('id'=>$v['userid']),'merchname');
		}else{
			$v['is']=0;
		}
		$v['action']='jy_jd/hotel//id='.$v['id'];
		$v['url']=custom_url($v['action'],true);
		//$v['location']=json_decode($v['location'],true);
		$v['address']=$v['province'].$v['city'].$v['district'].$v['address'];
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'酒店管理'),
			array('op'=>'edit','title'=>'添加酒店'),
		),
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：排序是绝对排序，越大越靠前，不受距离影响；推荐，星数会优先靠前，但是会受距离影响（只能优先60公里）','list'=>array(
			array('name'=>'star','title'=>'星数','type'=>'star','set'=>'star'),
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
			array('name'=>'title','title'=>'酒店名称','type'=>'string'),
			array('name'=>'saletype','title'=>'属性标签','type'=>'checkbox','options'=>'saletypes'),
			array('name'=>'image','title'=>'图片','type'=>'image'),
			array('name'=>'address','title'=>'地址','type'=>'string'),
			array('name'=>'is','title'=>'多商户','type'=>'radio','options'=>'is'),
			array('name'=>'merchtitle','title'=>'商户名称','type'=>'string'),
			array('name'=>'url','title'=>'二维码','type'=>'ewm'),
			array('name'=>'action','title'=>'系统短地址','type'=>'copy'),
			array('name'=>'tuijie','title'=>'推荐？','type'=>'switch','set'=>'set'),
		),
		'action'=>array(		
			array('type'=>'href','action'=>'room','title'=>'房型管理'),
			array('type'=>'href','action'=>'manage','title'=>'店员管理'),
			array('type'=>'href','action'=>'order','title'=>'订单管理'),
			array('type'=>'href','action'=>'member','title'=>'会员管理'),
		)
		),
	);
	$return['saletypes']=$this->saletypes;
	$return['htmls']=$htmls;
	$return['is']=array('0'=>'否','1'=>'是');
	exi($return);
	}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
	$item=pdo_get('jy_jd_hotel',array('id'=>$id));
	}else{
		$item=array();
	}
	$item['location']=array('district'=>$item['district'],'city'=>$item['city'],'province'=>$item['province']);
	$item['lat_lng']=json_decode($item['lat_lng'],true);
	$item['images']=json_decode($item['images'],true);
	$item['codeimg']=$item['codeimg']?json_decode($item['codeimg'],true):array();
    $return['item']=$item;
	$return['pcd']=cfc('tools')->pcd();
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'酒店设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'酒店管理'),
			array('op'=>'edit','title'=>'添加酒店')
		),
		'edit'=>array(
			array('name'=>'title','title'=>'酒店名称','type'=>'string'),
			array('name'=>'mobile','title'=>'联系电话','type'=>'string'),
			array('name'=>'userid','title'=>'所属商户','type'=>'select','options'=>'merchs','option_title'=>'merchname'),
			array('name'=>'image','title'=>'首页图片','type'=>'image'),
			array('name'=>'images','title'=>'多图','type'=>'images'),
			array('name'=>'location','title'=>'地区','type'=>'pcd','options'=>'pcd'),
			array('name'=>'address','title'=>'详细地址','type'=>'string'),
			array('name'=>'codeimg','title'=>'营业执照/许可证','type'=>'images'),
			array('name'=>'desc','title'=>'介绍','type'=>'text'),
			array('name'=>'content','title'=>'酒店详情','type'=>'richtext'),
			array('name'=>'remark','title'=>'退订规则','type'=>'richtext'),
			array('title'=>'下单页自定义文字','type'=>'title'),
			array('name'=>'diy_text01','title'=>'第一句','type'=>'text','help'=>'[iprice]表示押金变量！[tui_time]酒店房间取消订单当天时间！[tui_fee]退单手续费！'),
			array('name'=>'diy_text02','title'=>'第二句','type'=>'text','help'=>'[iprice]表示押金变量！[tui_time]酒店房间取消订单当天时间！[tui_fee]退单手续费！'),
			array('name'=>'diy_text03','title'=>'第三句','type'=>'text','help'=>'[iprice]表示押金变量！[tui_day]入住前天，[tui_time]酒店房间取消订单当天时间！[tui_fee]退单手续费！'),
			array('name'=>'lat_lng','title'=>'坐标','type'=>'lat_lng'),
			array('name'=>'msgmid','title'=>'消息提醒接收员','type'=>'choose','action'=>'core/member.get_member/'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'tuijie','title'=>'是否推荐','type'=>'switch'),
			array('name'=>'saletype','title'=>'属性标签','type'=>'checkbox','options'=>'saletypes'),
			array('name'=>'star','title'=>'星数','type'=>'radio','options'=>'star'),
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
		)
	);
	$return['saletypes']=$this->saletypes;
	$return['status']=array('0'=>'关闭','1'=>'开启');
	$return['star']=array('1'=>'1星','2'=>'2星','3'=>'3星','4'=>'4星','5'=>'5星');
	$return['merchs']=pdo_getall('jy_jd_user',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),array('id','merchname'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array_fields(array('diy_text01','diy_text02','diy_text03','userid','saletype','star','remark','tuijie','paixu','content','codeimg','status','title','msgmid','mobile','images','image','address','lat_lng','desc'),$postdata);
	//$data['location']=json_encode($data['location']);
	$data['province']=$postdata['location']['province'];
	$data['district']=$postdata['location']['district'];
	$data['city']=$postdata['location']['city'];
	$data['lat_lng']=ijson_encode($data['lat_lng']);
	$data['images']=ijson_encode($data['images']);
	$data['codeimg']=ijson_encode($data['codeimg']);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_jd_hotel',$data,array('id'=>$id));
		exi('设置成功！','','list');
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_jd_hotel',$data);
		exi('添加成功！','','list');
	}
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_jd_hotel',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_jd_hotel',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='star'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('参数错误！','error');
	}
	$update=array();
	$post=get_postdata();
	if(isset($post['star'])){
		$update['star']=$post['star'];
	}
	if($update){
		pdo_update('jy_jd_hotel',$update,array('id'=>$id));
	}
	exi('操作成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先操作商户！','error');
	}
	$post=get_postdata();
	if(isset($post['tuijie'])){
		pdo_update('jy_jd_hotel',array('tuijie'=>intval($post['tuijie'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
?>